home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
pdcurs21.zip
/
PRIVATE.ZIP
/
_CHADD.C
< prev
next >
Wrap
Text File
|
1992-11-21
|
7KB
|
213 lines
#define CURSES_LIBRARY 1
#include <curses.h>
#ifndef NDEBUG
char *rcsid__chadd = "$Header: c:/curses/private/RCS/_chadd.c%v 2.0 1992/11/15 03:24:16 MH Rel $";
#endif
/*man-start*********************************************************************
PDC_chadd() - Low level; Put a character to a window
PDCurses Description:
This is a private PDCurses function.
This routine will insert the character 'c' at the current cursor
position in the passed window.
If 'xlat' is TRUE, PDC_chadd() will handle things in a cooked
manner (tabs, newlines, carriage returns, etc). If 'xlat' is
FALSE, the characters are simply output directly.
If 'advance' is TRUE, PDC_chadd() will move the current cusor position
appropriately. The *addch functions call PDC_chadd() with noadvance TRUE,
while the *insch functions call PDC_chadd() with noadvance FALSE.
The normal curses routines (non-raw-output-mode) call PDC_chadd()
with 'xlat' TRUE.
PDCurses Return Value:
This function returns OK on success and ERR on error.
PDCurses Errors:
It is an error to call this function with a NULL window pointer.
Portability:
PDCurses int PDC_chadd( WINDOW* win, chtype ch, bool xlat, bool noadvance );
**man-end**********************************************************************/
int PDC_chadd(register WINDOW *win, chtype ch,bool xlat, bool advance)
{
int retval = ERR;
int x;
int y;
int newx;
chtype attr;
int ts;
if (win == (WINDOW *)NULL)
return( retval );
x = win->_curx;
y = win->_cury;
ts = win->_tabsize;
/* if the incoming character doesn't have its own attribute
then use the current attributes for the window.
if the incoming character has attributes but not a colour
component, or the attributes to the current attributes
for the window.
if the incoming character has a colour component use the
attributes solely from the incoming character */
if ((ch & A_ATTRIBUTES) == 0)
attr = win->_attrs;
else
if ((ch & A_COLOR) == 0)
attr = (ch & A_ATTRIBUTES) | win->_attrs;
else
attr = (ch & A_ATTRIBUTES);
ch = (ch & A_CHARTEXT);
if ((y > win->_maxy) ||
(x > win->_maxx) ||
(y < 0) ||
(x < 0))
{
return( retval );
}
if (xlat)
{
switch (ch) {
case '\t':
for (newx = ((x / ts) + 1) * ts; x < newx; x++)
{
if (waddch(win, ' ') == ERR)
{
return( retval );
}
/*
* if tab to next line
*/
if (win->_curx == 0)
{
/*
* exit the loop
*/
return( OK );
}
}
return( OK );
case '\n':
if (_cursvar.autocr && !(_cursvar.raw_out))
{
/*
* if lf -> crlf
*/
x = 0;
}
wclrtoeol( win );
if ((y = PDC_newline(win, y)) < 0)
return( retval );
if (advance)
{
win->_cury = y;
win->_curx = x;
}
return( OK );
case '\r':
if (advance)
win->_curx = x = 0;
return( OK );
case '\b':
if (--x < 0)
{
/*
* no back over left margin
*/
x = 0;
}
if (advance)
win->_curx = x;
return( OK );
case 0x7f:
if (waddch(win, '^') == ERR)
{
return( retval );
}
retval = waddch(win, '?');
return( retval );
default:
break;
} /* switch */
if (ch < ' ')
{
/*
* handle control chars
*/
if (waddch(win, '^') == ERR)
return( retval );
retval = (waddch(win, ch + '@'));
return( retval );
}
}
/*
* Add the attribute back into the character.
*/
ch |= attr;
if (win->_y[y][x] != ch)
{
/*
* only if data change
*/
if (win->_firstch[y] == _NO_CHANGE)
{
win->_firstch[y] = win->_lastch[y] = x;
}
else
{
if (x < win->_firstch[y])
{
win->_firstch[y] = x;
}
else
{
if (x > win->_lastch[y])
{
win->_lastch[y] = x;
}
}
}
}
win->_y[y][x++] = ch;
if (x >= win->_maxx)
{
/*
* wrap around test
*/
x = 0;
if ((y = PDC_newline(win, y)) < 0)
return( retval );
}
if (advance)
{
win->_curx = x;
win->_cury = y;
}
return( OK );
}